const {API, COMM} = getApp()

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    searchUrl: String,
  },

  /**
   * 组件的初始数据
   */
  data: {
    searchData: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onSearch(e) {
        this.search(e.detail)
    },
    
    search(txm) {
        let that = this
        API.get(that.data.searchUrl + "/" + txm).then(
            data => {
                that.triggerEvent('search', data)
            }
        ).catch(err => {
            wx.showToast({
              title: err,
              icon: 'error',
              duration: 2000
            })
            that.triggerEvent('search', null)
        });
    },

    onScanCode() {
        let that = this
        // 允许从相机和相册扫码
        wx.scanCode({
            success(res) {
                that.search(res.result)
            }
        })
    },
  }
})